/**
 * 系统管理--银行卡
 */
var bankcard = {
    id: "bankcardTable", //表格id
    seItem: null,		//选中的条目
    table: null,
    layerIndex: -1,
    condition: {
    }
};

/**
 * 初始化表格的列
 */
bankcard.initColumn = function () {
    return [
        {field: 'selectItem', radio: true},
        {
            title: '序号', field: 'number', width: 1, align: 'center', valign: 'middle', formatter: function (value, row, index) {
                return index + 1;
            }
        },
        {title: '姓名', field: 'cardName', align: 'center', valign: 'middle', sortable: true},
        {title: '联系电话', field: 'cardPhone', align: 'center', valign: 'middle', sortable: true},
        {title: '卡号', field: 'cardNumber', align: 'center', valign: 'middle', sortable: true},
        {title: '余额', field: 'cardMoney', align: 'center', valign: 'middle', sortable: true},
        {title: '操作', field: 'cardId', sortable: true, align: 'center', valign: 'middle', formatter: function (value, row, index) {
                return '<button type="button" class="btn btn-xs btn-success" onclick="bankcard.openEdit(\''+ row.cardId +'\')">修改信息</button>'
                    + '<button type="button" class="btn btn-xs btn-warning" onclick="bankcard.deleteCard()">解除绑定</button>'
            }}
    ];
};

/**
 * 点击了查看维修记录按钮
 * @param modifyId
 */
bankcard.openEdit = function(cardId){
    if(!cardId){
        return;
    }
    var selectId = cardId;
    if (!cardId) {
        selectId = this.seItem.cardId;
    }
    this.layerIndex = layer.open({
        type: 2,
        title: '修改信息',
        area: ['500px', '300px'],
        fix: false,
        maxmin: true,
        content: Feng.ctxPath + '/bankcard/bankcard_edit?cardId=' + selectId
    });
};


/**
 * 点击添加
 */
bankcard.openAdd = function () {
    this.layerIndex = layer.open({
        type: 2,
        title: '绑定银行卡',
        area: ['500px', '580px'],
        fix: false,
        maxmin: true,
        content: Feng.ctxPath + '/bankcard/bankcard_add'
    });
};

/**
 * 点击解除绑定
 */
bankcard.deleteCard = function () {
    var operation = function () {
        var ajax = new $ax(Feng.ctxPath + "/bankcard/delete", function () {
            Feng.success("删除成功!");
            window.location.reload();
        }, function (data) {
            Feng.error("删除失败!" + data.responseJSON.message + "!");
        });
        ajax.start();
    };
    Feng.confirm("是否解除绑定?", operation);
};

$(function () {

    bankcard.app = new Vue({
        el: '#bankCardPage',
        data: bankcard.condition
    });
    var defaultColunms = bankcard.initColumn();
    var table = new BSTable("bankcardTable", "/bankcard/list", defaultColunms);
    table.setPaginationType("client");
    bankcard.table = table.init();
    laydate.render({
        elem: '#timeLimit',
        range: true,
        theme: '#009efb',
        max: Feng.currentDate()
    });
});